#ifndef _IIC_H_
#define _IIC_H_
#include "pin_mux.h"
#include "fsl_common.h"
#include "fsl_gpio.h"
#include "ft6636.h"
//软件模拟IIC配置(只能在同一个端口的引脚作为IIC)
#define SOFT_SCL_GPIO BOARD_INITPINS_TP_SCL_GPIO
#define SOFT_SCL_PORT BOARD_INITPINS_TP_SCL_PORT
#define SOFT_SCL_PIN BOARD_INITPINS_TP_SCL_PIN

#define SOFT_SDA_GPIO BOARD_INITPINS_TP_SDA_GPIO
#define SOFT_SDA_PORT BOARD_INITPINS_TP_SDA_PORT
#define SOFT_SDA_PIN BOARD_INITPINS_TP_SDA_PIN

#define SDA_IN()   {  gpio_pin_config_t TP_SDA_config = {.pinDirection = kGPIO_DigitalInput,.outputLogic = 1};\
    GPIO_PinInit(SOFT_SDA_GPIO, SOFT_SDA_PORT, SOFT_SDA_PIN, &TP_SDA_config);}
#define SDA_OUT()   {  gpio_pin_config_t TP_SDA_config = {.pinDirection = kGPIO_DigitalOutput,.outputLogic = 1};\
    GPIO_PinInit(SOFT_SDA_GPIO, SOFT_SDA_PORT, SOFT_SDA_PIN, &TP_SDA_config);}

union LenData
{
    uint32_t iic_data;
    uint8_t data[4];
};
uint32_t IIC_TIMEOUT_UserCallback(int8_t errorCode);
enum IIC_FQ
{
    IIC_FQ_400 = 400, IIC_FQ_200 = 200, IIC_FQ_100 = 100, IIC_FQ_300 = 300,IIC_FQ_NULL = 0
};
enum ACK
{
  NMACK = 0,
  MACK = !NMACK
} ;

void SetSoftIIC_Config( enum IIC_FQ fq);
int32_t IIC_WriteByte(uint8_t writeAddr,const uint8_t buffer);
int32_t IIC_ReadByte(uint8_t readAddr, uint8_t *buffer);
int32_t IIC_LenWrite(void *, uint8_t writeAddr, const uint8_t *buf ,uint16_t len);
int32_t IIC_LenRead(void *, uint8_t readAddr, uint8_t *buf,uint16_t len );
void Soft_iic_start(void);
void Soft_iic_stop(void);
void Soft_iic_ack(void);
void Soft_iic_nack(void);
int8_t Soft_wait_ack(void);
int8_t Soft_iic_Read(void);
void Soft_iic_Write(int8_t data);

#endif
